package com.smcaiot.jftorg.domain;

import com.smcaiot.jftorg.config.TestMybatisPlusConfig;
import com.smcaiot.jftorg.domain.org.OrgId;
import com.smcaiot.jftorg.domain.user.User;
import com.smcaiot.jftorg.south.adapter.UserRepositoryAdapter;
import com.smcaiot.jftorg.south.mapper.JftUserMapper;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;

/**
 * @Author: cz
 * @Date: 2023/9/28
 * @Description:
 */
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = TestMybatisPlusConfig.class)
public class UserRepositoryIT {
    private UserRepositoryAdapter userRepository;
    @Autowired
    private JftUserMapper jftUserMapper;

    private final OrgId userId = OrgId.from("M023116");

    @Before
    public void setUp() throws Exception {
        userRepository = new UserRepositoryAdapter();
        ReflectionTestUtils.setField(userRepository, "userMapper", jftUserMapper, JftUserMapper.class);
    }

    @Test
    public void should_return_user_when_get_user() {
        User user = userRepository.getUser(userId);
        Assertions.assertThat(user).isNotNull();
        Assertions.assertThat(user.getOrgId()).isEqualTo(userId);
    }
}
